package funjava;

/**
 * Created by judasnow on 5/16/16.
 */

interface Measurable {
    double getMeasure();

}

class Employee2 implements Measurable {

    double i;

    public String getName() {
        return name;
    }

    String name;

    public Employee2(String name, double i) {
        this.name = name;
        this.i = i;
    }

    public double getMeasure() {
        return i;
    }

    static public double average(Measurable[] objects) {
        double sum = 0;
        for (Measurable m: objects) {
            sum += m.getMeasure();
        }

        return sum / objects.length;
    }

    /**
     * 返回工资最高的员工
     */
    static public String largest(Measurable[] objects) {
        double max = 0;

        if (objects.length == 0) {
            // 返回 null 是不对的
            return null;
        } else {
            Measurable maxEmployee = objects[0];

            for (Measurable m : objects) {
                if (m.getMeasure() > max) {
                    maxEmployee = m;
                }
            }

            // 父类向子类进行转换
            Employee2 e2 = (Employee2)maxEmployee;
            return e2.getName();
        }
    }
}

public class C3_1 {
    public static void main(String[] args) {
        Employee2 e1 = new Employee2("judasnow", 1);
        Employee2 e2 = new Employee2("snow", 2);
        Employee2 e3 = new Employee2("ok", 3);

        System.out.print(Employee2.average(new Measurable[] {e1, e2, e3}));
    }
}
